'''
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with self work for additional information
 * regarding copyright ownership.  The ASF licenses self file
 * to you under the Apache License, Version 2.0 (the
 * "License") you may not use self file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http:#www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
'''
from base.java.NoSuchElementException import NoSuchElementException
from base.rdf.NodeIterator import NodeIterator
from base.util.iterator.impl.NiceIterator import NiceIterator

#import java.util.NoSuchElementException;
#import java.util.Iterator;

#import org.apache.jena.rdf.model.*;
#import org.apache.jena.util.iterator.*;

'''
 * An internal class not normally of interest to developers.
 * A sequence node iterator.
'''


# NiceIterator<RDFNode>
class SeqNodeIteratorImpl(NiceIterator, NodeIterator):
    # Seq seq
    # int size
    # int index = 0
    # Statement stmt = null
    # Iterator<Statement> base

    # private int numDeleted = 0

    '''
     * Creates SeqNodeIteratorImpl
    '''

    # param Iterator<Statement> iterator, Seq seq
    def __init__(self, iterator, seq):
        super().__init__()
        self.base = iterator
        self.seq = seq
        self.size = seq.size()
        self.index = 0
        self.stmt = None
        self.numDeleted = 0

    # @Override
    # param 
    # result boolean
    def hasNext(self):
        return self.base.hasNext()

    # @Override
    # param 
    # result RDFNode
    def next(self):
        self.stmt = self.base.next()
        self.index += 1
        return self.stmt.getObject()

    # @Override
    # param 
    # result RDFNode
    def nextNode(self):
        return self.next()

    # @Override
    # param 
    # result void
    def remove(self):
        if self.stmt is None:
            raise NoSuchElementException()
        # ((ContainerI) seq).remove(index - numDeleted, stmt.getObject())
        self.seq.remove(self.index - self.numDeleted, self.stmt.getObject())
        self.stmt = None
        self.numDeleted += 1
